import React, { Component } from 'react';
import { ActionSheet, Toast } from 'antd-mobile';

// fix touch to scroll background page on iOS
// https://github.com/ant-design/ant-design-mobile/issues/307
// https://github.com/ant-design/ant-design-mobile/issues/163
// const isIPhone = new RegExp('\\biPhone\\b|\\biPod\\b', 'i').test(window.navigator.userAgent);
// eslint-disable-line no-unused-vars

// if (isIPhone) {
//   var wrapProps = {
//     onTouchStart: e => e.preventDefault(),
//   };
// }

class Footer extends Component {
  constructor (props) {
    super(props)
    this.state = {
      clicked: 'none',
      clicked1: 'none',
      clicked2: 'none',
    }
  }
  dataList = [
    { url: 'OpHiXAcYzmPQHcdlLFrc', title: '发送给朋友' },
    { url: 'wvEzCMiDZjthhAOcwTOu', title: '新浪微博' },
    { url: 'cTTayShKtEIdQVEMuiWt', title: '生活圈' },
    { url: 'umnHwvEgSyQtXlZjNJTt', title: '微信好友' },
    { url: 'SxpunpETIwdxNjcJamwB', title: 'QQ' },
  ].map(obj => ({
    icon: <img src={`https://gw.alipayobjects.com/zos/rmsportal/${obj.url}.png`} alt={obj.title} style={{ width: 36 }} />,
    title: obj.title,
  }));

  showShareActionSheet = () => {
    ActionSheet.showShareActionSheetWithOptions({
      options: this.dataList,
      // title: 'title',
      message: '分享到',
    },
    (buttonIndex) => {
      this.setState({ clicked1: buttonIndex > -1 ? this.dataList[buttonIndex].title : 'cancel' });
      // also support Promise
      return new Promise((resolve) => {
        // Toast.info('1秒后关闭');
        // setTimeout(resolve, 1000);
        resolve()
      });
    });
  }
  getiptValue(){
   const content=document.getElementsByTagName('input')[0].value
   const uid= localStorage.getItem('uid')
   const newsId=this.props.getValtoF.props.match.params.id
   if(uid === null || uid === ''){
    Toast.info('请先登录')
   }else{
     if(content===''){
      Toast.info('内容不能为空')
     }else{
      fetch(`http://106.13.34.4:8080/new/comment?uid=${uid}&newsId=${newsId}&content=${content}`)
      .then(res => res.json())
      .then(data =>{
        // console.log(data)
        if(data.code===1){
          Toast.info('评论成功');
          // window.location.reload()
          // console.log(this)
          fetch(`http://106.13.34.4:8080/new/getComment?newsId=${newsId}`)
            .then(re=>re.json())
            .then(da =>{
              let pingLun = da.data
              let str = ''
              pingLun.reverse().map(value=>{
                str+=`<Item wrap >${value.content}<span>评论发布时间：${value.time}</span></Item>`
              })
              this.props.getPingLun(str)
            })
        }
      })
     }
   }
  }
  addMyLike(){
    const uid= localStorage.getItem('uid')
    if(uid) {
      const newsId=this.props.getValtoF.props.match.params.id
      fetch(`http://106.13.34.4:8080/new/collection?uid=${uid}&newsId=${newsId}`)
        .then(res => res.json())
        .then(data =>{
          // console.log(data)
          Toast.info('收藏成功！')
        })
    } else {
      Toast.info('请先登录！')
    }
  }
  render () {
    return (
      <footer className="footer">
        <input type="text" placeholder="发表评论" />
        <span className="iconfont icon-comment-pen" onClick= {this.getiptValue.bind(this)}></span>
        <span className="iconfont icon-shoucang" onClick= {this.addMyLike.bind(this)}></span>
        <span className="iconfont icon-fenxiang-copy" onClick={this.showShareActionSheet}></span>
      </footer>
    )
  }
}
export default Footer